from elasticsearch import Elasticsearch
from ssl import create_default_context
#线上
#context = create_default_context(cafile="/home/Genshin_Impact/ca/node.pem")
#线下
context = create_default_context(cafile="C:/Users/123/Desktop/yuanshen/ca/node.pem")
context.check_hostname = False
obj = Elasticsearch("https://127.0.0.1:9200",ssl_context=context, http_auth=('elastic','banben'))

def data_search(key,page=0,page_size=3):
    query= {
    "from": page, "size": page_size,
    "query": {
        "bool": {
            "should": [

                {"match": {
                    "results.sharer.name": key
                }},
                {
                    "match": {
                        "results.detail_page.synopsis": key
                    }
                },
                {
                    "match": {
                        "results.sharer.title": key
                    }
                },
                {
                    "match": {
                        "results.name": key
                    }
                }
            ]
        }
    }
}






    return  obj.search(index="king",doc_type='_doc',body=query,request_timeout=30)
if __name__ == '__main__':
 print(data_search(''))